package com.mcode.blog.controller;

import com.mcode.blog.common.cache.Cache;
import com.mcode.blog.service.CategoryService;
import com.mcode.blog.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("categorys")
@RestController
public class CategoryController {

    @Resource
    private CategoryService categoryService;


    /**
     * 分类列表
     * @return
     */
    @GetMapping
    @Cache(expire = 5 * 60 * 1000, name = "list_cate")
    public Result listCategory() {
        return Result.success(categoryService.selectCate());
    }


    /**
     * 分类列表
     * @return
     */
    @GetMapping("detail")
    @Cache(expire = 5 * 60 * 1000, name = "list_cate_d")
    public Result findAllDetail() {
        return Result.success(categoryService.selectCate());
    }


    /**
     * 分类详情
     * @param id 分类id
     * @return
     */
    @GetMapping("detail/{id}")
    @Cache(expire = 5 * 60 * 1000, name = "detail_cate")
    public Result categoryDetail(@PathVariable("id") Long id) {
        return Result.success(categoryService.cateDetailById(id));
    }

}
